package com.ajouroid.smartcoworker;
import java.io.File;

import android.app.Activity;

public class DeleteCache {

	public void clearCache(Activity act) {
		final File cacheDirFile = act.getCacheDir();
		if (null != cacheDirFile && cacheDirFile.isDirectory()) {
			clearSubCacheFiles(cacheDirFile);
		}
	}

	private void clearSubCacheFiles(File cacheDirFile) {
		if (null == cacheDirFile || cacheDirFile.isFile()) {
			return;
		}
		for (File cacheFile : cacheDirFile.listFiles()) {
			if (cacheFile.isFile()) {
				if (cacheFile.exists()) {
					cacheFile.delete();
				}
			} else {
				clearSubCacheFiles(cacheFile);
			}
		}
	}
}
